Skip to content

[Core] Fix vOp operations truncating the target vector when an operand is empty - #6445

Open
alxbilger wants to merge 1 commit into
sofa-framework:masterfrom
alxbilger:fixvop
Open

alxbilger wants to merge 1 commit into
sofa-framework:masterfrom
alxbilger:fixvop

Conversation

@alxbilger

Copy link
Copy Markdown
Contributor

While replacing accumulateForce with vOp in #6441, a lot of unit tests started failing. The cause: the vOp_* helpers did vv.resize(vb.size()), so when the external force vector is empty (the usual case), the force vector was resized to 0 and everything accumulated so far was lost.

Changes in MechanicalObject.inl:

  • accumulating ops (v += b, v += bk, v = vk + b) no longer shrink v: they
    only grow it if b is larger, and only loop over b's size. Nothing is added
    when b is empty.
  • those ops, and v *= k, now use a WriteAccessor instead of a WriteOnlyAccessor,
    since they read v and need it to be up to date if it's dirty.
  • ops that overwrite v keep the WriteOnlyAccessor, with a comment saying why.
  • loops are bounded by the size of the operands, so we never read past the end.

[with-all-tests]


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@alxbilger alxbilger added pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI labels Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant